package demo2;

public class LeetCode202 {
    public boolean isHappy(int n) {
        int slow = n, fast = num(n);
        while(slow != fast) {
            slow = num(slow);
            fast = num(fast);
            fast = num(fast);
        }
        return slow == 1;
    }
    public static int num(int n) {
        int num = 0;
        while(n > 0) {
            int tmp = n % 10;
            num += tmp * tmp;
            n /= 10;
        }
        return num;
    }
}
